'use strict'
import React, { createClass, PropTypes } from 'react'
import { withRouter } from 'react-router'
import { connect } from 'react-redux'
import $ from 'jquery'
import GoodList from '../components/GoodList'
import ExchangeModal from '../components/ExchangeModal'
import { setExchangeModalData, setGlobalData } from '../actions'


const GoodPage = withRouter(createClass({
    componentDidMount() {
        $('body').css('backgroundColor', '#fff');
                const listType = this.props.params.listType;
                this.props.router.setRouteLeaveHook(this.props.route, () => {
                    $('#exchangeModal').modal('hide');
        });
    },
    render() {
        const { goodData, globalData, setGlobalData, setExchangeModalData } = this.props;
        return (<div>
            <GoodList setExchangeModalData={setExchangeModalData} />
            <ExchangeModal dialogId="exchangeModal" goodData={goodData} globalData={globalData} setGlobalData={setGlobalData} />
        </div>)
    }
}));

const mapStateToProps = (state) => {
    return {
        goodData: state.goodList,
        globalData: state.globalData
    }
};

export default connect(mapStateToProps, {setExchangeModalData, setGlobalData})(GoodPage);
